<?php

class XQL_Simple_InsertQuery extends XQL_SimpleQuery
{
	protected $executionMode = XQL_Query::MODE_EXEC;
	protected $isResultAutoincrement = TRUE;

	public function __construct($querySetName, $connectionAlias='default')
	{
		parent::__construct($querySetName, $connectionAlias);

		if (!$this->isQueryLoaded())
		{
			$this->setAction(
				XQL_Insert::create()->
				join(
					XQL_Table::create()->set(
						XQL_Item::create()->set(':table')
					)
				)->
				join(
					XQL_InsertCols::create()->set(
						XQL_Item::create()->set(':cols')
					)
				)->
				join(
					XQL_Values::create()->set(
						XQL_Item::create()->set(':values')
					)
				)
			);
		}
	}

	/**
	 * Visszad egy példányt az osztályból.
	 *
	 * @return XQL_Simple_InsertQuery
	 */
	static public function create($querySetName, $connectionAlias='default')
	{
		return new XQL_Simple_InsertQuery($querySetName, $connectionAlias);
	} // static method

	protected function onBeforeExecute($args)
	{
		if (count($args) == 1)
		{
			$cols = XQL_Util::argumentToFields(array_keys($args[0]));
			$values = XQL_Util::argumentToValueList(array_values($args[0]));
			$rep = array(
				':table'	=> (string)$this->table,
				':cols'		=> implode(', ', $cols),
				':values'	=> $values
			);
			$this->query = str_replace(array_keys($rep), array_values($rep), $this->query);
		}
		else
		{
			//throw new eSimpleInsertQuery(eSimpleInsertQuery::PARAM_COUNT_NOT_ENOUGH);
		}

		return $this;
	}
}

?>